<? php
/**
 * Account API
 *
 * Provides access and CRUD mechanism for accounts.
 *
 * @author Terence Yan <terence.yan@me.com>
 */
 
 //Note from Vicky: Depending on your directory, these two lines may need to be changed
 
require_once(__DIR__.'/CommonClass/errorcode.php');
require_once(__DIR__.'/account.controller.php');

/**
 * Delete Account
 * @param $userName account id
 * @param $authUser
 * @param $authUserPassHash
 * @param $datahash hash of existing data
 * @return array success error code.
 */
function deleteAccount($username, $authUsername, $authPass, $dataHash) {
    if (empty($username)){
        return array(ErrorCode::failRead + 100);
    }
    if (empty($authUsername)) {
        return array(ErrorCode::failRead + 200);
    }
    if (empty($authPass)) {
        return array(ErrorCode::failRead + 300);
    }
    if (empty($dataHash)) {
        return (ErrorCode::failRead + 400);
    }

    $controller = new AccountController();
    if(!($controller -> authenticateValidator($authUsername, $authPass))){
        return array(ErrorCode::authFailDelete);
    }
    if (!($controller -> managerValidator($authUsername))) {
        return array(ErrorCode::authFailDelete);
    }
    return $controller -> deleteHandler(array(
        ':accName' => $username,
        'dataHash' => $dataHash
    ));
}


?>